package com.wd.health.model.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.health.R;
import com.wd.health.model.bean.ByqBean;
import com.wd.health.view.activity.ByqxqActivity;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @ProjectName:shopmall
 * @Package:com.bawei.myhealth.model.adapter
 * @ClassName:ByqAdapter02
 * @UpdateUser: 裴童童
 * @date: 2020/12/11
 */
public class ByqAdapter02 extends RecyclerView.Adapter<ByqAdapter02.ViewHolder>{
    private List<ByqBean.ResultBean> list;
    private Context context;
    private SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public ByqAdapter02(List<ByqBean.ResultBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(context, R.layout.item_byq,null));
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        holder.title.setText(list.get(position).getTitle());
        long releaseTime = list.get(position).getReleaseTime();
        String format = simpleDateFormat.format(releaseTime);
        holder.time.setText(format);
        holder.context.setText(list.get(position).getDetail());
        holder.sc.setText("收藏"+list.get(position).getCollectionNum());
        holder.jy.setText("建议"+list.get(position).getCommentNum());
        final int amount = list.get(position).getAmount();
        if (amount==0){
            holder.xsj.setText("");
        }else {
            holder.xsj.setText(amount+"");
            holder.xsj.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.h_currency,0,0,0);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int sickCircleId = list.get(position).getSickCircleId();
                Intent intent = new Intent(holder.itemView.getContext(), ByqxqActivity.class);
                intent.putExtra("id",amount);
                holder.itemView.getContext().startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView title;
        private final TextView time;
        private final TextView sc;
        private final TextView jy;
        private final TextView xsj;
        private final TextView context;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.tv_byq_title);
            time = itemView.findViewById(R.id.tv_byq_time);
            sc = itemView.findViewById(R.id.tv_byq_sc);
            jy = itemView.findViewById(R.id.tv_byq_jy);
            xsj = itemView.findViewById(R.id.tv_byq_xsj);
            context = itemView.findViewById(R.id.tv_byq_context);
        }
    }
} 
